package com.xiaohao.server.parkmap.controller;

import com.xiaohao.server.parkmap.entity.ResponseResult;
import com.xiaohao.server.parkmap.entity.ShopItem;
import com.xiaohao.server.parkmap.service.ShopItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("shop")
public class ShopItemController {
    @Autowired
    private ShopItemService shopItemService;

    @GetMapping("{id}")
    public ResponseResult<ShopItem> query(@PathVariable Integer id) {
        return ResponseResult.success(shopItemService.queryById(id));
    }

    @GetMapping
    public ResponseResult<List<ShopItem>> query(ShopItem shopItem) {
        return ResponseResult.success(shopItemService.query(shopItem));
    }

    @DeleteMapping("{id}")
    public ResponseResult<Void> delete(@PathVariable Integer id) {
        return shopItemService.delete(id) > 0 ? ResponseResult.success() : ResponseResult.error();
    }

    @PostMapping
    public ResponseResult<Void> save(@RequestBody ShopItem shopItem) {
        return shopItemService.save(shopItem) > 0 ? ResponseResult.success() : ResponseResult.error();
    }
}
